package com.wing.warehouse.controller.admin.service;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wing.common.utils.JsonResult;
import com.wing.warehouse.dao.WarehouseCustodyPriceDao;
import com.wing.warehouse.model.entity.WarehouseCustodyPriceEntity;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class WarehouseCustodyPriceServiceImpl extends ServiceImpl<WarehouseCustodyPriceDao, WarehouseCustodyPriceEntity> implements WarehouseCustodyPriceService {

    @Override
    public Page<WarehouseCustodyPriceEntity> pageList4app(Page page, Map<String, Object> params) {
        List<WarehouseCustodyPriceEntity> list = baseMapper.list4app(page, params);
        page.setRecords(list);
        return page;
    }

    @Override
    public JsonResult saveWarehouseProductType(WarehouseCustodyPriceEntity warehouseProductType) {
        JsonResult jsonResult = new JsonResult<>();
        if (ObjectUtil.isNotEmpty(warehouseProductType)){
            baseMapper.insert(warehouseProductType);
            return jsonResult.success("添加成功");
        }else {
            return jsonResult.fail("添加失败");
        }
    }

    @Override
    public JsonResult update(WarehouseCustodyPriceEntity warehouseProductType) {
        JsonResult jsonResult = new JsonResult<>();
        if (ObjectUtil.isNotEmpty(warehouseProductType)){
            baseMapper.updateById(warehouseProductType);
            return jsonResult.success("修改成功");
        }else {
            return jsonResult.fail("修改失败");
        }
    }


    @Override
    public JsonResult deleteWarehouseProductType (Long warehouseProductTypeId){
        JsonResult jsonResult = new JsonResult<>();
        if (warehouseProductTypeId != null){
            WarehouseCustodyPriceEntity warehouseProductTypeEntity = this.getById(warehouseProductTypeId);
            warehouseProductTypeEntity.setIsDeleted(true);
            baseMapper.updateById(warehouseProductTypeEntity);
            return jsonResult.success("删除成功");
        }else {
            return jsonResult.fail("删除失败");
        }
    }
}
